home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z11.ADF / LOGO / LOGOSOURCE / logoparse.c < prev    next >
C/C++ Source or Header  |  1987-07-21  |  5KB  |  282 lines

  1.  
  2. #include "logo.h"
  3. extern int multnum,endflag,rendflag,topf;
  4. extern char ibuf[];
  5. extern char *ibufptr, *getbpt, charib;
  6. extern int letflag,pflag;
  7. #ifdef PAUSE
  8. extern int pauselev;
  9. #endif
  10. extern FILE *pbuf;
  11. extern struct lexstruct keywords[];
  12. extern struct alist *locptr;
  13. extern struct runblock *thisrun;
  14.  
  15. struct object *makeword(c)
  16. int c;
  17. {
  18.     register struct object* obj;
  19.     register char *s;
  20.     char str[100];
  21.  
  22.     s=str;
  23.     do {
  24.         if (c == '\\') c = getchar()|0200;
  25.         else if (c == '%') c = ' '|0200;
  26.         *s++ = c;
  27.     } while((c=getchar())>0 && !index(" \t\n[]",c));
  28.     if (c<=0) {
  29.         printf("Unmatched [ in procedure.\n");
  30.         errhand();
  31.     }
  32.     charib = c;
  33.     *s = '\0';
  34.     obj = objcpstr(str);
  35.     if (nump(obj)) {
  36.         obj = numconv(localize(obj),"!makeword");
  37.         mfree(globcopy(obj));    /* unlocalize */
  38.         return(obj);
  39.     }
  40.     return(globcopy(obj));
  41. }
  42.  
  43. struct object *makel1()
  44. {
  45.     register struct object *head,*tail;
  46.     register c,cnt;
  47.  
  48.     while ((c=getchar())==' ' || c=='\t' || c=='\n') ;
  49.     if(c==']') {
  50.         charib = c;
  51.         return ((struct object *)0);
  52.     }
  53.     if (c<=0) {
  54.         printf("Unmatched [ in procedure.\n");
  55.         errhand();
  56.     }
  57.     head = (struct object*)ckmalloc(sizeof(struct object));
  58.     tail = head;
  59.     cnt = 0;
  60.     head->obtype = CONS;
  61.     head->refcnt = 0;
  62.     head->obcdr = 0;
  63. loop:
  64.     if (c=='[') {
  65.         tail->obcar = globcopy(makel1());
  66.         getchar();    /* gobble the peeked close bracket */
  67.     } else {
  68.         tail->obcar = makeword(c);
  69.         /* This used to use charib instead of passing the char as
  70.          * an argument, but that loses if the first char of a word
  71.          * is backslash, in which case something is already in
  72.          * charib from getchr1. */
  73.     }
  74.     while ((c=getchar())==' ' || c=='\t' || c=='\n') ;
  75.     if (c==']') {
  76.         charib = c;
  77.         return (head);
  78.     }
  79.     if (c<=0) {
  80.         printf("Unmatched [ in procedure.\n");
  81.         errhand();
  82.     }
  83.  
  84.     tail->obcdr = (struct object*)ckmalloc(sizeof(struct object));
  85.     tail = tail->obcdr;
  86.     tail->obtype = CONS;
  87.     tail->refcnt = 1;
  88.     tail->obcdr = 0;
  89.  
  90.     goto loop;
  91. }
  92.  
  93. struct object *makelist()
  94. {
  95.     return(localize(makel1()));
  96. }
  97.  
  98. #ifdef DEBUG
  99. getchr1()
  100. #else
  101. getchar()
  102. #endif
  103. {
  104.     FAST c;
  105. #ifdef AMIGA
  106.     extern int quitsig;
  107.  
  108.     if (quitsig) {
  109.         quitsig = 0;
  110.         sigquit();
  111.     }
  112. #endif
  113.  
  114.     if (charib) {
  115.         c=charib;
  116.         charib=0;
  117.         return(c);
  118.     }
  119.     else if (pflag==1) {
  120.         while ((c=getc(pbuf))=='\r')
  121.             ;
  122.         if (c=='\\' && letflag!=1) {    /* continuation line feature */
  123.             c=getc(pbuf);
  124.             if (c=='\n') c=getc(pbuf);
  125.             else {
  126.                 charib = c;
  127.                 c = '\\';
  128.             }
  129.         }
  130.         if (!letflag && c>='A' && c<='Z') c+= 32;
  131.         return(c);
  132.     }
  133.     else if (getbpt) {    /* BH 5/19/81 moved down below pflag test */
  134.         c = *getbpt++;
  135.         if (c) return (c);
  136.         if (!thisrun) {
  137.             getbpt = 0;
  138.             return('\n');
  139.         }    /* startup file feature */
  140.         --getbpt;
  141.         if (--(thisrun->rcount) <= 0) {
  142.             if (!rendflag) rendflag = 1;    /* BH 3/17/83 */
  143.             return(0);
  144.         } else {
  145.             rerun();
  146.             return('\n');
  147.         }
  148.     }
  149.     else if (ibufptr==NULL) {
  150.     rebuff:
  151.         if ((c=read(0,ibuf,IBUFSIZ))==IBUFSIZ)
  152.             if (ibuf[IBUFSIZ-1]!='\n') {
  153.                 while (read(0,ibuf,IBUFSIZ)==IBUFSIZ)
  154.                     if (ibuf[IBUFSIZ-1]=='\n') break;
  155.                 puts("Your line is too long.");
  156.                 errhand();
  157.             }
  158.         if (c<0) {
  159.             /* Error return from read.  Probably signal. */
  160.             return ('\n');
  161.         }
  162.         if (c==0) {
  163.             /* Not clear what's right for EOF.  I'd just ignore it
  164.                only what if stdin is a file, we'll loop forever.
  165.                Compromise: if we're paused, don't lose the valuable
  166.                context with a keystroke, otherwise, exit. */
  167. #ifdef PAUSE
  168.             if (pauselev) return('\n');
  169. #endif
  170.             leave(3);
  171.         }
  172.         ibufptr=ibuf;
  173.     }
  174.     c= *ibufptr++;
  175.     if (c=='\\' && letflag!=1) {    /* continuation line feature */
  176.         c = *ibufptr++;
  177.         if (c=='\n') {
  178.             ibufptr=NULL;
  179.             goto rebuff;    /* sorry, Jay */
  180.         } else {
  181.             charib = c;
  182.             c = '\\';
  183.         }
  184.     }
  185.     if (!letflag && c>='A' && c<='Z') c+=32;
  186.     if (c=='\n') ibufptr=NULL;
  187.     return(c);
  188. }
  189.  
  190. #ifdef DEBUG
  191. getchar()
  192. {    /* BH 3/23/80 debugging echo output */
  193.     register c;
  194.  
  195.     c = getchr1();
  196.     if (memtrace) putchar(c);
  197.     return(c);
  198. }
  199. #endif
  200.  
  201. struct object *multiop(op,args)
  202. register op;
  203. register struct object *args;
  204. {
  205.     extern struct object *list();
  206.  
  207.     if (keywords[op].lexval==list) return (localize(args));
  208.     else if (multnum<2) {
  209.         nputs(keywords[op].word);
  210.         puts(" needs at least two inputs.");
  211.         errhand();
  212.     } else if (multnum==2)
  213.         return ((*keywords[op].lexval)(localize(args->obcar),
  214.               localize(args->obcdr->obcar)));
  215.     else {
  216.         multnum--;
  217.         return ((*keywords[op].lexval)(localize(args->obcar),
  218.               multiop(op,args->obcdr)));
  219.     }
  220. }
  221.  
  222. struct object *pots()
  223. {
  224. #ifndef AMIGA
  225.     register f;
  226.  
  227.     if (f=fork()) while (wait(0)!=f) ;
  228.     else {
  229.         execl ("/bin/sh","sh","-c",POTSCMD,0);
  230.         exit();
  231.     }
  232. #else
  233.     char pat[10], buf[128], *fn, *scdir();
  234.     FILE *fp;
  235.  
  236.     pat[0] = '*';
  237.     strcpy(&pat[1], EXTEN);
  238.     while (fn = scdir(pat)) {
  239.         fp = fopen(fn, "r");
  240.         if (fp) {
  241.             fgets(buf,128,fp);
  242.             printf("%s", buf);
  243.             fclose(fp);
  244.         }
  245.     }
  246. #endif
  247.  
  248.     return((struct object *)-1);
  249. }
  250.  
  251. lbreak() {
  252. #ifdef PAUSE
  253.     if (!pflag && thisrun && thisrun->str==(struct object *)(-1))
  254.         unpause();
  255. #endif
  256.     if (!pflag && thisrun) {
  257.         rendflag = 1;    /* BH 3/17/83 */
  258.         if (thisrun->rprev && !(thisrun->svpflag)) rendflag++;
  259.     }
  260. }
  261.  
  262. lstop() {
  263.     endflag = 1;
  264. #ifdef PAUSE
  265.     if (!pflag && thisrun && thisrun->str==(struct object *)(-1))
  266.         unpause();
  267. #endif
  268.     if (!pflag && thisrun) rendflag = 3;    /* BH 3/17/83 */
  269. }
  270.  
  271. ltopl() {
  272.     topf=1;
  273.     errwhere();
  274.     errzap();
  275.     leave(1);
  276. }
  277.  
  278. lbyecom() {
  279.     leave(3);
  280. }
  281.  
  282.